#!/usr/bin/env python
from google.appengine.ext.webapp import RequestHandler
from google.appengine.api import users, images
from google.appengine.ext import db

from templates import run, render, redirect
from models import UserActions,Photos


class Thumbnail(RequestHandler):
	def get(self):
		img = self.request.uri.split('/')[4]
		image = Photos.all()
		image.filter('nickname = ', img.replace('%40', '@'))
		
		if not image[0].thumbnail:
		    self.response.out.write("")
		else:
		    self.response.headers['Content-Type'] = "image/png"
		    self.response.out.write(image[0].thumbnail)

class Profile(RequestHandler):
	def get(self):
		img = self.request.uri.split('/')[4]
		image = Photos.all()
		image.filter('nickname = ', img.replace('%40', '@'))
		if not image[0].profile:
		    self.response.out.write("")
		else:
		    self.response.headers['Content-Type'] = "image/png"
		    self.response.out.write(image[0].profile)
		
def main():
	run([('/thumbnail/.*', Thumbnail),('/profile/.*', Profile)])
if __name__ == '__main__': main()
